package com.example.demo2.service.impl;

import com.example.demo2.dao.TestMapper;
import com.example.demo2.service.ICheckService;
import com.example.demo2.service.ITestCase4NestedService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import static com.example.demo2.utils.HttpUtils.check;

@Slf4j
@Service
public class TestCase4NestedServiceImpl implements ITestCase4NestedService {

    @Autowired
    private TestMapper testMapper;
    @Autowired
    private ICheckService checkService;


    @Transactional(propagation = Propagation.NESTED)
    @Override
    public void insertAndCheck() {
        testMapper.insert("case4.4.2");
        check();
        log.info("插入 case4.4.2 之后， 应该是什么都查不到的");
        checkService.check();
        log.info("事务内部这里可以查到 case4.4.1 case4.4.2");
    }
}
